/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hoja.pkg3;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Mardiego
 */
public class Fichero {
    
    String s;
    int can;
    public Fichero()
    {
        this.s= "numeros_gir08118.txt" ;
        this.can=2000;
    }
    
    public void crearArchivo()
    {
        File archivo=new File(s);
			try{
			  BufferedWriter bw =new BufferedWriter(new FileWriter(s));
		
		   	  // Escribimos 
                          for(int i=0; i<can; i++)
                          {
                              double num=Math.random();
                              num=num*2000;
                              bw.write((int)num+"");
                              bw.newLine();
                          }

			  // Hay que cerrar el fichero
			  bw.close();
			} catch (IOException ioe){
				ioe.printStackTrace();
			}		
    }
    
    public List leerArchivo()
    {
        List lista=new ArrayList();
        try
        {
        FileReader rd=new FileReader(s);
        BufferedReader leer=new BufferedReader(rd);
        String y;
        int contador=0;
        while ((y=leer.readLine())!=null)
        {
            if (y.contains(" "))
            {
                y=y.substring(0,y.length()-2);
            }
            lista.add(Integer.parseInt(y));
            contador++;
        }
        rd.close();
        
        }
                  catch (FileNotFoundException fnfe){
			fnfe.printStackTrace();
		} catch (IOException ioe){
			ioe.printStackTrace();
		}
        return lista;
    }
    
}